﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using App.Domain.Contracts;
using Microsoft.Practices.ServiceLocation;
using App.Web.Models;
using App.Domain.Handlers;

namespace App.Web.Controllers
{
    public class HomeController : AuthorizedController
    {

        public HomeController(IUserServices userServices,
            IServiceLocator serviceLocator)
            : base(userServices, serviceLocator)
        {
        }
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var siginleft = new SignInViewModel() { 
            
                User = null,
                NewsList = Using<GetNewsAll>().Execute().Take(5),
            
            };

            return View(siginleft);
        }

        public ActionResult Register(RegistViewModel register)
        {
            if (register.Recruiter == null || register.Company==null)
                return View();

            var company = register.Company;
            company.Id = Guid.NewGuid();
            company.DateCreated = DateTime.Now;
            company.LastUpdated = DateTime.Now;
            Using<CreateCompany>().Execute(company);

            var recruiter = register.Recruiter;
            recruiter.Id = Guid.NewGuid();
            recruiter.CompanyId = company.Id;
            recruiter.DateCreated = DateTime.Now;
            recruiter.LastUpdated = DateTime.Now;
            recruiter.ExpiryDate = DateTime.Now;
            Using<CreateRecruiter>().Execute(recruiter);

            return this.RedirectToAction("Index", "Home");
        }

        [HttpPost]
        public ActionResult Regist()
        {
            return View();
        }

    }
}
